const { contextBridge, ipcRenderer } = require('electron/renderer')

contextBridge.exposeInMainWorld('electronAPI', {
	show: (x, y, text) => ipcRenderer.send('tooltip:show', { x, y, text }),
	hide: () => ipcRenderer.send('tooltip:hide'),
	linkRedBookRoom: () => ipcRenderer.send('link-redbook-room'),
	redbookRoomStatus: () => ipcRenderer.invoke('redbook-room-status'),
	onRedbookRoomStatusChanged: (callback) => ipcRenderer.on('on-redbook-room-status-changed', (_, status) => callback(status)),
	removeOnRedbookRoomStatusChanged: () => ipcRenderer.removeAllListeners('on-redbook-room-status-changed'),
	onReceivedMsg: (callback) => ipcRenderer.on('received-msg', (_, msg) => callback(msg)),
	removeOnReceivedMsg: () => ipcRenderer.removeAllListeners('received-msg'),
	allMobileScene: () => ipcRenderer.invoke('mobile-scene'),
	selectMobileScene: (index) => ipcRenderer.send('select-mobile-scene', index),
	createMobileScene: () => ipcRenderer.invoke('create-mobile-scene'),
	currentMobileSceneData: () => ipcRenderer.invoke('current-mobile-scene-data'),
	onCurrentMobileSceneChanged: (callback) => ipcRenderer.on('on-current-mobile-scene-changed', (_, currentScene) => callback(currentScene)),
	removeOnCurrentMobileSceneChanged: () => ipcRenderer.removeAllListeners('on-current-mobile-scene-changed'),
	mobileSceneIsEdit: () => ipcRenderer.invoke('mobile-scene-is-edit'),
	mobileSceneEditChangeTo: (edit) => ipcRenderer.send('mobile-scene-edit-change-to', edit),
	mobileSceneIsEditChanged: (callback) => ipcRenderer.on('mobile-scene-is-edit-changed', (_, edit) => callback(edit)),
	removeMobileSceneIsEditChanged: () => ipcRenderer.removeAllListeners('mobile-scene-is-edit-changed'),
	showAddComponentsWin: () => ipcRenderer.send('show-add-components-win'),
	addComponent: (cpt_name, style) => ipcRenderer.send('add-component', cpt_name, style),
	goToselectCurrentScene: () => ipcRenderer.send('go-to-select-current-scene'), // 让index选中当前场景编辑
	onGoToSelectCurrentSceneHtml: (callback) => ipcRenderer.on('go-to-select-current-scene-html', (_, index) => callback(index)), // 让index选中当前场景编辑
	removeOnGoToSelectCurrentSceneHtml: () => ipcRenderer.removeAllListeners('go-to-select-current-scene-html'), // 移除 让index选中当前场景编辑
	addUserAlert: () => ipcRenderer.send('add-user-alert'),
	editUserAlert: (index) => ipcRenderer.send('edit-user-alert', index),
	selectImage: () => ipcRenderer.invoke('select-image'),
	selectGifAlert: (userInfo, from) => ipcRenderer.send('select-gif-alert', userInfo, from),
	selectGift: (gift, to) => ipcRenderer.send('select-gift', gift, to),
	onSelectGiftToHtml: (callback) => ipcRenderer.on('on-select-gift-to-html', (_, gift) => callback(gift)),
	removeOnSelectGiftToHtml: () => ipcRenderer.removeAllListeners('on-select-gift-to-html'),
	finishUser: (userInfo, uType, from) => ipcRenderer.send('finish-user', userInfo, uType, from),
	userList: (table_user_temp, cpt_id) => ipcRenderer.invoke('user-list', table_user_temp, cpt_id),
	delUser: (userInfo) => ipcRenderer.send('del-user', userInfo),
	getEditUserInfo: () => ipcRenderer.invoke('get-edit-user-info'),
	getSceneWithIndex: (index) => ipcRenderer.invoke('get-scene-with-index', index),
	sceneChanged: (scene, index, cpt_index, cloudDb, from) => ipcRenderer.send('scene-changed', scene, index, cpt_index, cloudDb, from),
	noticeSceneChanged: (callback) => ipcRenderer.on('notice-scene-changed', (_, scene, index, cpt_index, from) => callback(scene, index, cpt_index, from)),
	removeNoticeSceneChanged: () => ipcRenderer.removeAllListeners('notice-scene-changed'),
	noticeUserListChanged: (callback) => ipcRenderer.on('notice-user-list-changed', (_, userList, from) => callback(userList, from)),
	removeNoticeUserListChanged: () => ipcRenderer.removeAllListeners('notice-user-list-changed'),
	changeUserInfo: (userInfo, index, cloudDb, from) => ipcRenderer.send('change-user-info', userInfo, index, cloudDb, from),
	updateUserCptTemp: (userCptTemp, from) => ipcRenderer.send('update-user-cpt-temp', userCptTemp, from),
	noticeUserCptTempChanged: (callback) => ipcRenderer.on('notice-user-cpt-temp-changed', (_, from) => callback(from)),
	removeNoticeUserCptTempChanged: () => ipcRenderer.removeAllListeners('notice-user-cpt-temp-changed'),
	hiddenMobile: () => ipcRenderer.send('hidden-mobile'),
	mobileFrameMoni: () => ipcRenderer.invoke('mobile-frame-mopni'),
	mobileFrameMoniChangeTo: (moni) => ipcRenderer.send('mobile-frame-mopni-to', moni),
	onMobileFrameMoniChanged: (callback) => ipcRenderer.on('on-mobile-frame-mopni-changed', (_, moni) => callback(moni)),
	removeOnMobileFrameMoniChanged: () => ipcRenderer.removeAllListeners('on-mobile-frame-mopni-changed'),
	mobileFrameIsMin: () => ipcRenderer.invoke('mobile-frame-is-min'),
	mobileFrameSetMinOrMax: (min) => ipcRenderer.send('mobile-frame-set-min-or-max', min),
	onMobileFrameSetMinOrMax: (callback) => ipcRenderer.on('on-mobile-frame-set-min-or-max', (_, min) => callback(min)),
	removeOnMobileFrameSetMinOrMax: () => ipcRenderer.removeAllListeners('on-mobile-frame-set-min-or-max'),
	getConsole_story: (lastId, type) => ipcRenderer.invoke('get-console-story', lastId, type),
	onConsole_storyAdd: (callback) => ipcRenderer.on('on-consoloe-story-add', (_, story) => callback(story)),
	removeOnConsole_storyAdd: () => ipcRenderer.removeAllListeners('on-consoloe-story-add'),
	getAllFansSort: () => ipcRenderer.invoke('get-all-fans-sort'),
	onFansSortChanged: (callback) => ipcRenderer.on('on-fans-sort-changed', (_,) => callback()),
	removeOnFansSortChanged: () => ipcRenderer.removeAllListeners('on-fans-sort-changed'),
	systemSetting: (setting) => ipcRenderer.invoke('get-system-setting', setting),
	systemSettingChangeTo: (setting, value, from) => ipcRenderer.send('system-setting-change-to', setting, value, from),
	onSystemSettingChanged: (callback) => ipcRenderer.on('on-system-setting-changed', (_, settingVal, from) => callback(settingVal, from)),
	removeSystemSettingChanged: () => ipcRenderer.removeAllListeners('on-system-setting-changed'),
	getNowFansSort: () => ipcRenderer.invoke('get-now-fans-sort'),
	showBindTo: (fans_id, user_id, x, y) => ipcRenderer.send('show-bind-to', fans_id, user_id, x, y),
	getBindToList: (type) => ipcRenderer.invoke('get-bind-to-list', type),
	changeBindTo: (user_id, type) => ipcRenderer.send('change-bind-to', user_id, type),
	saveGift: (url, fileName) => ipcRenderer.send('save-gift', url, fileName),
	getGiftsStory: () => ipcRenderer.invoke('get-gifts-story'),
	showGiftResendTo: (gift_id, rev_user_id, x, y) => ipcRenderer.send('show-gift-resend-to', gift_id, rev_user_id, x, y),
})